﻿@{
    ViewBag.Title = "Edit";
    Layout = "../Shared/_Layout.cshtml";
}
@using mscook.mvc;
@model mscook.mvc.Areas.weblogin.Models.MagazineModel
@section JavaScript{
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.validate.unobtrusive.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/scripts/jquery.unobtrusive-ajax.js")"></script>
}
@Html.Partial("_MultiBtnModalLoder")
<div id="resourceTypeModal" class=" modal hide fade form-horizontal">
</div>

<div class="row-fluid sortable">
    <div class="box span12">
        <div class="box-header well">
        </div>
        <div class="box-content">
            @using (Html.BeginForm("Edit", "magazine", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal" }))
            {

                <fieldset>
                    <legend>期刊编辑</legend>

                    <div class="control-group">
                        <label class="control-label">标题</label>
                        <div class="controls">
                            <div class="input-prepend">
                                <input type="hidden" name="Id" value="@Model.Magazine.Id" />
                                @Html.TextBoxFor(magazine => Model.Magazine.Title, new { size = "16" })
                            </div>
                            @Html.ValidationMessageFor(magazine => Model.Magazine.Title)
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">年份</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @Html.TextBoxFor(magazine => Model.Magazine.Year, new { size = "16" })
                            </div>
                            @Html.ValidationMessageFor(magazine => Model.Magazine.Year)
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">期数</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @Html.TextBoxFor(magazine => Model.Magazine.Volume, new { size = "16" })
                            </div>
                            @Html.ValidationMessageFor(magazine => Model.Magazine.Volume)
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">所需积分</label>
                        <div class="controls">
                            <div class="input-prepend">
                                @Html.TextBoxFor(magazine => Model.Magazine.AbsBonus, new { size = "16" })
                            </div>
                            @Html.ValidationMessageFor(magazine =>  Model.Magazine.AbsBonus)
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">类型</label>
                        <div class="controls">
                            <div class="input-prepend">

                                @{
                var names = "";
                var ids = "";
                int count = Model.ResourceTypes.Count;
                for (int i = 0; i < count; i++)
                {
                    var item = Model.ResourceTypes.ElementAt(i);
                    names += item.Name;
                    ids += item.Id;

                    if (count - 1 != i)
                    {
                        names += ",";
                        ids += ",";
                    }
                }
                                    
                                    @Html.TextBox("MagazineTypeName", names, new { @readonly = "true" })
                                    @Html.Hidden("MagazineTypeId", ids)
                                }

                            </div>
                            <button id="resourceTypeModalBtn" type="button" class="btn btn-primary multimodalLoder" data-num="1" data-link-name="MagazineTypeName" data-link-id="MagazineTypeId" data-link-modal="resourceTypeModal" data-type="Magazine" data-url="/weblogin/resourcetype/MultiResourceTypeModal"><i class="icon-edit icon-white"></i></button>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">图片</label>
                        <div class="controls">
                            <div class="input-prepend" style="width: 400px">
                                <!--<img src="~/Upload/default/@Model.Magazine.ImageName"/>-->
                                @if (string.IsNullOrEmpty(Model.Magazine.ImageName))
                                {
                                    <img id="preview" style="display: none; width: 100%" />
                                }
                                else
                                {
                                    <img id="preview"  style="width:100%" src="~/Upload/@Model.Magazine.ImageName"  />
                                }
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">图片上传</label>
                        <div class="controls">

                            <div class="fileupload @(string.IsNullOrEmpty(Model.Magazine.ImageName) ? "fileupload-new" : "fileupload-exists")" data-provides="fileupload">
                                <span class="btn btn-file">
                                    <span class="fileupload-new">请选择图片</span>
                                    <span class="fileupload-exists">更改图片</span>
                                    <input name="related_content_image[0]" type="file" />
                                </span>
                                <span class="fileupload-preview">@Model.Magazine.ImageName</span>
                                <input name="existed_related_content_image[0]" value="@Model.Magazine.ImageName" type="hidden" />
                                <a href="#" class="close fileupload-exists" data-dismiss="fileupload" style="float: none">×</a>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary btn-large">保存</button>
                    </div>
                </fieldset>
            }
        </div>
    </div>
    <!--/span-->

</div>
